﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FacturIT.Service.User;

namespace Factur_IT.Account
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLoginIn_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Text;

            int? userid = FacturIT.Service.FacturITManager.Instance.ReadUserFromDatabase(username, password).UserID;
            if (userid == null)
            {
                txtUsername.Text = string.Empty;
                txtPassword.Text = string.Empty;
            }
            else
            {
                int UserID = Convert.ToInt32(userid);
                Session["LoggedIn"] = true;
                Session.Timeout = 60;
                UserDTO user = FacturIT.Service.FacturITManager.Instance.ReadUser(UserID);
                Session["UserID"] = user.UserID;
                Session["UserName"] = username;
                Session["UserFullName"] = user.Fullname;

                Response.Redirect("~/default.aspx");
            } 
        }
    }
}